﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using demo.DBHelper;
using demo.Entity;
using demo.IService;

namespace demo.Service
{
    public class UserService : RepositoryDao<Users>,IUserService
    {
        /// <summary>
        /// 是否存在可用的账号
        /// </summary>
        /// <param name="account">账号</param>
        /// <returns></returns>
        public bool IsExists(string account)
        {
            var sql = new StringBuilder();
            sql.Append("select count(1) from User where Account=@Account ");
            return base.Exists(sql.ToString(), new {Account = account});
        }

        /// <summary>
        /// 通过账号密码获得实体
        /// </summary>
        /// <param name="account">账号</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        public Users GetByAccAndPwd(string account, string password)
        {
            var sql = new StringBuilder();
            sql.Append("select * from Users where Account=@Account and Password=@Password ");
            return base.GetList(sql.ToString(), new { Account = account, Password = password }).FirstOrDefault();
        }
        /// <summary>
        /// 修改实体
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns></returns>
        public bool UpdateModel(Users model)
        {
            return base.Update(new Users[1] { model }, new string[] { "Password"});
        }
    }
}
